package com.jubaozan.service.platform.controller.admin;

import com.jubaozan.c3.framework.constants.Constants;
import com.jubaozan.c3.framework.utils.ResultHolder;
import com.jubaozan.dao.youme.domain.SysUser;
import com.jubaozan.modules.validation.tools.ValidationUtils;
import com.jubaozan.service.platform.constants.PlatformResultEnum;
import com.jubaozan.service.platform.decorator.PlatformUserDecorator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.Pattern;

/**
 * @Auther: chenjingui
 * @Date: 2020/9/23 18:51
 * @Description:
 */
@Api(tags = {"平台用户管理"}, value = "平台用户管理")
@RestController
@RequestMapping("/platformUser")
public class PlatformUserController {
    @Autowired
    PlatformUserDecorator platformUserDecorator;
    @ApiOperation(value = "用户登陆")
    @PostMapping("/login")
    public ResultHolder login(@Pattern(regexp = ValidationUtils.REGEX_MOBILE, message = "手机号码格式不正确") @RequestParam String mobile, @RequestParam(Constants.KEY_PWD) String pwd) {
        if(StringUtils.isEmpty(mobile) || StringUtils.isEmpty(pwd)){
            return ResultHolder.error(PlatformResultEnum.PLAT_USERNAME_OR_PWD_IS_NULL.getCode(),PlatformResultEnum
                    .PLAT_USERNAME_OR_PWD_IS_NULL.getMsg());
        }
        return platformUserDecorator.login(mobile,pwd);
    }
    @ApiOperation(value = "用户注册")
    @PostMapping("/register")
    public ResultHolder register(@RequestParam SysUser sysUser)
            throws Exception {
        if(StringUtils.isEmpty(sysUser)){
            return ResultHolder.error(PlatformResultEnum.PLAT_PARAM_IS_NULL.getCode(),PlatformResultEnum
                    .PLAT_PARAM_IS_NULL.getMsg());
        }
        return platformUserDecorator.register(sysUser);
    }
}
